
from selenium import webdriver # 导入webdriver包
from  pprint import pprint
import json
import time

post = {}

driver = webdriver.Chrome() # 初始化一个谷歌浏览器实例：driver

driver.maximize_window() # 最大化浏览器

driver.get("https://mp.weixin.qq.com") # 通过get()方法，打开一个url站点

time.sleep(2) # 暂停5秒钟

driver.find_element_by_xpath("/*//div[@id='header']/div[2]/div/div/form/div[1]/div[1]/div/span/input").clear()


driver.find_element_by_xpath("/*//div[@id='header']/div[2]/div/div/form/div[1]/div[1]/div/span/input").send_keys('1260567175@qq.com')

driver.find_element_by_xpath("//*[@id='header']/div[2]/div/div/form/div[1]/div[2]/div/span/input").clear()
driver.find_element_by_xpath("//*[@id='header']/div[2]/div/div/form/div[1]/div[2]/div/span/input").send_keys('QQ19970924')
time.sleep(15)
driver.find_element_by_xpath("//*[@id='header']/div[2]/div/div/form/div[1]/div[2]/div/span/input").click()
driver.find_element_by_xpath("//*[@id='header']/div[2]/div/div/form/div[4]/a").click()

time.sleep(15)
driver.get("https://mp.weixin.qq.com")
cookie_items = driver.get_cookies()
for cookie_item in cookie_items:
    post[cookie_item['name']] = cookie_item['value']
cookie_str = json.dumps(post)
with open('cookie.txt','w+',encoding='utf-8') as f:
    f.write(cookie_str)